import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { AchievementMajorData } from "../data/AchievementMajorData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../../extend/language/Language";
import { AchievementBonusItem } from "./AchievementBonusItem";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { ImagesConst } from "../../../resource/ImagesConst";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ProgressBase } from "../../player/ProgressBase";
import { AchievementGetBonusButton } from "./AchievementGetBonusButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class AchievementMajorCellRender
    
    export  class AchievementMajorCellRender extends CellRenderer
    {
        constructor()
        {
            super();
            this.initStyles();
            this.initView();
            this.mouseEnabled = false;
            this.mouseChildren = true;
            this._btnGet.addEventListener(flash.events.MouseEvent.CLICK, this.clickGetBonusHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (arg1 == null) 
            {
                return;
            }
            this._myData = arg1 as AchievementMajorData;
            this._btName.bitmapData = GlobalClass.getBitmap(this.ResNames[this._myData.categoryId]).bitmapData;
            this._txtLevel.text = Language.getStringByParam(80060, this._myData.curLevel.toString());
            this._bar.setValue(this._myData.curAchievement, this._myData.upLevelAchievement);
            while (this._icon.numChildren > 0) 
            {
                this._icon.removeChildAt(0);
            }
            this._icon.addChild(new AchievementBonusItem(this._myData.bonusCode, 1));
            if (this._myData.isFinished()) 
            {
                this._btnGet.enabled = true;
                this._btnGet.mouseEnabled = true;
                this._btnGet.label = Language.getString(80256);
                this._btnGet.visible = true;
                this._icon.visible = true;
                if (this._iconYiDaChengRight != null) 
                {
                    this._iconYiDaChengRight.visible = false;
                }
            }
            else 
            {
                this._btnGet.enabled = false;
                this._btnGet.mouseEnabled = false;
                this._btnGet.label = Language.getString(80255);
                this._btnGet.visible = true;
                if (this._iconYiDaChengRight != null) 
                {
                    this._iconYiDaChengRight.visible = false;
                }
            }
            if (this._myData.isLast && this._myData.hasGotBonus) 
            {
                this._btnGet.visible = false;
                DisplayUtil.removeAllChild(this._icon);
                if (this._iconYiDaChengRight == null) 
                {
                    this._iconYiDaChengRight = GlobalClass.getBitmap(ImagesConst.AchievementFinished);
                    this._iconYiDaChengRight.x = 337;
                    this._iconYiDaChengRight.y = 4;
                    this.addChild(this._iconYiDaChengRight);
                }
                this._iconYiDaChengRight.visible = true;
            }
            return;
        }

        /* internal  */clickGetBonusHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (flash.utils.getTimer() < this._lastClickTime + this.GetBonuseTimeSpace) 
            {
                return;
            }
            if (!this._myData.isFinished()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80258));
                return;
            }
            if (this._myData.hasGotBonus && this._myData.isLast) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80259));
                return;
            }
            this._lastClickTime = flash.utils.getTimer();
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementGetLevelUpBonus, this._myData));
            return;
        }

        /* internal  */initStyles(): void
        {
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            this._btName = new Object /* flash.display.Bitmap */();
            this._btName.x = 10;
            this._btName.y = 18;
            this.addChild(this._btName);
            this._txtLevel = ObjCreate.createGTextField("", 98, 18, 80, 20, this, new GTextFormat("", null, 130583));
            this._bar = new ProgressBase();
            this._bar.x = 139;
            this._bar.y = 21;
            this._bar.width = 130;
            this._bar.height = 9;
            this._bar.progressBarClass = "Mofatiao";
            this._bar.setValue(0, 100);
            this.addChild(this._bar);
            this._icon = new Object /* flash.display.Sprite */();
            this._icon.x = 290;
            this._icon.y = 13;
            this._icon.buttonMode = false;
            this.addChild(this._icon);
            this._btnGet = new AchievementGetBonusButton(344, 16, this);
            var loc2=ObjCreate.createBg(9, 56, 385, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */createProgressBars(arg1: string, arg2: int, arg3: string): ProgressBase
        {
            var loc1;
            (loc1 = ObjCreate.createTextField("", 50, 5 + arg2 * 32, 40, 20, this)).htmlText = "<font color=\'#ffff00\'>" + arg1 + "</font>";
            var loc2;
            (loc2 = new ProgressBase()).x = 10;
            loc2.y = 20 + arg2 * 32;
            loc2.progressBarClass = arg3;
            loc2.setValue(5542, 6515);
            this.addChild(loc2);
            return loc2;
        }

        /* internal */ /* const */GetBonuseTimeSpace: int=800;

        /* internal */ /* const */ResNames: Array<any>=[ImagesConst.AchievementCategoryJuese, ImagesConst.AchievementCategoryJuese, ImagesConst.AchievementCategoryZhuangbei, ImagesConst.AchievementCategoryShehui, ImagesConst.AchievementCategoryXianmeng, ImagesConst.AchievementCategoryPVP, ImagesConst.AchievementCategoryCaifu, ImagesConst.AchievementCategoryPVE, ImagesConst.AchievementCategoryYincang, ImagesConst.AchievementCategoryMingren];

        /* internal */ /* var */_btName: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtLevel: GTextFiled;

        /* internal */ /* var */_bar: ProgressBase;

        /* internal */ /* var */_icon: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnGet: AchievementGetBonusButton;

        /* internal */ /* var */_myData: AchievementMajorData;

        /* internal */ /* var */_iconYiDaChengRight: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_lastClickTime: int=0;
    }
